<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="util.*"%>
<%@page import="dal.*"%>
<%@ page import="model.*,java.util.*"%>
<%
	GenericDal<TaskModel, TaskModelExt> dal = new GenericDal<TaskModel, TaskModelExt>(
			new TaskModel());
	TaskModelExt queryCount = new TaskModelExt();
	int count = dal.count(queryCount);

	int pageIndex = 1;
	if (request.getParameter("pageIndex") != null
			&& !request.getParameter("pageIndex").isEmpty()) {
		try {
			pageIndex = Integer.parseInt(request
					.getParameter("pageIndex"));
		} catch (Exception e) {
		}
	}

	int pageSize = 20;
	if (request.getParameter("pageSize") != null
			&& !request.getParameter("pageSize").isEmpty()) {
		try {
			pageSize = Integer.parseInt(request
					.getParameter("pageSize"));
		} catch (Exception e) {
		}
	}

	int noOfPage = count / pageSize;
	if (count % pageSize > 0) {
		noOfPage++;
	}

	TaskModelExt query = new TaskModelExt();
	query.setLimit(pageSize);
	query.setOffset((pageIndex - 1) * pageSize);
	List<TaskModel> list = dal.selectList(query);

	boolean embedded = false;
	if (request.getParameter("embedded") != null
			&& !request.getParameter("embedded").isEmpty()) {

		if (request.getParameter("embedded").equalsIgnoreCase("true")
				|| request.getParameter("embedded").equalsIgnoreCase(
						"1")) {
			embedded = true;
		}
	}
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Task List</title>

<link rel="stylesheet" href="css/common.css" />
<link rel="stylesheet" href="css/jquery-ui-1.8.14.custom.css"
	type="text/css" />
<link rel="stylesheet" href="css/jquery-ui-timepicker.css"
	type="text/css" />
<link rel="stylesheet" href="css/hyjack.css" type="text/css" />
<link rel="stylesheet" href="css/datepicker.css" />

<script language="javascript" type="text/javascript"
	src="js/datepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/common.js"></script>
<script language="javascript" type="text/javascript"
	src="js/jquery-1.6.1.js"></script>
<script language="javascript" type="text/javascript"
	src="js/jquery-1.5.1.min.js"></script>
<script language="javascript" type="text/javascript"
	src="js/jquery.hyjack.select.js"></script>
<script language="javascript" type="text/javascript"
	src="js/jquery.ui.core.min.js"></script>
<script language="javascript" type="text/javascript"
	src="js/jquery.ui.widget.min.js"></script>

<script language="javascript" type="text/javascript"
	src="js/jquery.ui.timepicker.js"></script>
<script language="javascript" type="text/javascript"
	src="js/datepicker.js"></script>
<script language="javascript" type="text/javascript"
	src="js/jquery.hyjack.js"></script>
<script language="javascript" type="text/javascript"
	src="js/ajaxQuickInsert.js"></script>

<link rel="stylesheet" href="css/listForm.css" />

</head>
<body>
	<%
		if (!embedded) {
	%>
	<jsp:include page="menu.jsp"></jsp:include>
	<br />
	<%
		}
	%>
	<table class="tblPaging">
		<tr class="trPaging">
			<td class="tdPaging">
				<%
					for (int i = 1; i <= noOfPage; i++) {
						if (i == pageIndex) {
				%> <span class="lblPaging"><%=i%></span> <%
 	} else {
 %> <a class="hrefPaging"
				href="taskList.jsp?pageIndex=<%=i%>&pageSize=<%=pageSize%>"><%=i%></a>
				<%
					}
					}
				%>
			</td>
		</tr>
	</table>
	<br />
	<table class="tblList">
		<tr class="tblListHeader">
			<td class="tdListHeader"></td>
			<td class="tdListHeader"></td>
			<th class="thListHeader">Id</th>
			<th class="thListHeader">Name</th>
			<th class="thListHeader">Code</th>
			<th class="thListHeader">Description</th>
			<th class="thListHeader">Id Employee</th>
			<th class="thListHeader">Id Type</th>
			<th class="thListHeader">Id Phase</th>
			<th class="thListHeader">Status</th>
			<th class="thListHeader">Plan Start Time</th>
			<th class="thListHeader">Plan End Time</th>
			<th class="thListHeader">Real Start Tate</th>
			<th class="thListHeader">Real End Time</th>
			<th class="thListHeader">Need Approval</th>
			<th class="thListHeader">Is Event</th>
			<th class="thListHeader">Is Draft</th>
			<th class="thListHeader">Notification</th>
			<th class="thListHeader">Created</th>
			<th class="thListHeader">Creator</th>
			<th class="thListHeader">Updated</th>
			<th class="thListHeader">Updator</th>
			<th class="thListHeader">Deleted</th>
			<th class="thListHeader">Deletion Time</th>
			<th class="thListHeader">Rate</th>
			<th class="thListHeader">Is Group</th>
			<th class="thListHeader">Id Parent</th>

			<td class="tdListHeader"></td>
		</tr>

		<%
			int size = list.size();
			for (int i = 0; i < size; i++) {
				TaskModel obj = list.get(i);
		%>

		<tr class="trListItem">
			<td class="tdListInt"><%=i + 1%></td>
			<td class="tdListHref"><a
				href="task?mode=edit&id=<%=obj.getId()%>
">Edit</a></td>

			<td class="tdListText"><%=obj.getNameToString()%></td>
			<td class="tdListText"><%=obj.getCodeToString()%></td>
			<td class="tdListTextarea"><%=obj.getDescriptionToString()%></td>
			<td class="tdListInt"><%=obj.getIdEmployeeToString()%></td>
			<td class="tdListInt"><%=obj.getIdTypeToString()%></td>
			<td class="tdListInt"><%=obj.getIdPhaseToString()%></td>
			<td class="tdListInt"><%=obj.getStatusToString()%></td>
			<td class="tdListDateTime"><%=StringUtil.toDateTimeString(obj.getPlanStartTime())%></td>
			<td class="tdListDateTime"><%=StringUtil.toDateTimeString(obj.getPlanEndTime())%></td>
			<td class="tdListDateTime"><%=StringUtil.toDateTimeString(obj.getRealStartTate())%></td>
			<td class="tdListDateTime"><%=StringUtil.toDateTimeString(obj.getRealEndTime())%></td>
			<td class="tdListBool"><%=HtmlUtil.genHtml(obj.getNeedApproval())%></td>
			<td class="tdListBool"><%=HtmlUtil.genHtml(obj.getIsEvent())%></td>
			<td class="tdListBool"><%=HtmlUtil.genHtml(obj.getIsDraft())%></td>
			<td class="tdListInt"><%=obj.getNotificationToString()%></td>
			<td class="tdListDateTime"><%=StringUtil.toDateTimeString(obj.getCreated())%></td>
			<td class="tdListInt"><%=obj.getCreatorToString()%></td>
			<td class="tdListDateTime"><%=StringUtil.toDateTimeString(obj.getUpdated())%></td>
			<td class="tdListInt"><%=obj.getUpdatorToString()%></td>
			<td class="tdListBool"><%=HtmlUtil.genHtml(obj.getDeleted())%></td>
			<td class="tdListDateTime"><%=StringUtil.toDateTimeString(obj.getDeletionTime())%></td>
			<td class="tdListInt"><%=obj.getRateToString()%></td>
			<td class="tdListBool"><%=HtmlUtil.genHtml(obj.getIsGroup())%></td>
			<td class="tdListInt"><%=obj.getIdParentToString()%></td>

			<td class="tdListHref"><a
				href="task?mode=delete&id=<%=obj.getId()%>
">Edit</a></td>
		</tr>
		<%
			}
		%>
	</table>
	<br />
	<table class="tblPaging">
		<tr class="trPaging">
			<td class="tdPaging">
				<%
					for (int i = 1; i <= noOfPage; i++) {
						if (i == pageIndex) {
				%> <span class="lblPaging"><%=i%></span> <%
 	} else {
 %> <a class="hrefPaging"
				href="taskList.jsp?pageIndex=<%=i%>&pageSize=<%=pageSize%>"><%=i%></a>
				<%
					}
					}
				%>
			</td>
		</tr>
	</table>
</body>
</html>